//拼接请求前缀
$.ajaxPrefilter(function(option) {
    console.log(option);
    option.url = 'http://api-breakingnews-web.itheima.net' + option.url

    //添加统一的请求头配置
    if (option.url.includes('/my/')) {
        option.headers = {
            Authorization: localStorage.getItem('token') || ''
        }
    }

     //成功或失败都会执行
     option.complete = function(res) {
        console.log(res);
        if (res.responseJSON.status ===1 && res.responseJSON.message === '身份认证失败！') {
            //强制清空token
            localStorage.removeItem('token')
            //强制跳转到登录页面
            location.href = '/login.html'
        }
    }
    
})